public class Day08 {
    public static void main(String[] args) {
//        System.out.println(Integer.parseInt("01"));
//        String s = "1";
//        String[] split = s.split("-");
        Day08 day08 = new Day08();
        System.out.println(day08.dayOfYear("2004-03-01"));
    }

    // 拼写单词
    public int countCharacters(String[] words, String chars) {
        int[] charsNums = checkCharacterNums(chars);
        int ret = 0;
        for(int i = 0; i < words.length; i++) {
            int[] wordsNums = checkCharacterNums(words[i]);
            ret += subNums(charsNums, wordsNums);
        }
        return ret;
    }
    // 统计字符个数
    private int[] checkCharacterNums(String s) {
        int[] nums = new int[26];
        for(int i = 0; i < s.length(); i++) {
            nums[s.charAt(i) - 'a'] += 1;
        }
        return nums;
    }

    // 获取总共减去字符的个数
    private int subNums(int[] charsNums, int[] wordsNums) {
        int ret = 0;

        for(int i = 0; i < charsNums.length; i++) {
            // 先判断能不能减
            if(charsNums[i] < wordsNums[i]) {
                // 对应的字符比较少
                return 0;
            }
            // 减去
            ret += wordsNums[i];
        }

        return ret;
    }

    //
    public int dayOfYear(String date) {
        int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        String[] dates = date.split("-");
        days[1] += isLeap(Integer.parseInt(dates[0])); // 将 2月 +1/+0
        int month = Integer.parseInt(dates[1]);
        int totalDay = Integer.parseInt(dates[2]);
        for(int i = 0; i < month - 1; i++) {
            totalDay += days[i];
        }
        return totalDay;
    }

    // 是闰年返回 1 不是返回 0
    private int isLeap(int year) {
        return year % 400 == 0 || year % 100 != 0 && year % 4 == 0 ? 1 : 0;
    }
}
